package cn.felord.debezium.mina;


import cn.felord.debezium.service.TcpActService;
import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.codec.StringDecoder;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;

@Component
public class MinaServer9001 {
    @Value("${socket.port}")
    private Integer port;
    @Autowired
    private TcpActService senMessageService2x;

    public static boolean isRun = false;
    public void start() throws IOException {
        IoAcceptor acceptor = new NioSocketAcceptor();
//        acceptor.getFilterChain().addLast("logger", new LoggingFilter());
//        acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
//        acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory()));

        // 设置处理类
        acceptor.setHandler(new TimeServerHandler9001erw(senMessageService2x));
        acceptor.bind(new InetSocketAddress(port));
        isRun = true;
        System.out.println("2线mina 启动 "+ port +"===");
//        System.out.println(senMessageService2x);
    }
}

